//角色是否是转移伤害的目标-设置
Game_Battler.prototype.setTransferDamageFlag = function(value){
    this._transferDamageFlag = !!value;
};

//角色是否是转移伤害的目标-返回
Game_Battler.prototype.isDamageTransfered = function(){
    return !!this._transferDamageFlag;
};

//转移伤害播放：声音和动画
Game_Battler.prototype.performTransferDamage = function(){
    if(!$gameSystem.isSideView() && this.isActor())
        return;
    const animationId = this.transferDamageAnimationId();
    const mirror = this.isActor();
    this.startAnimation(animationId, mirror, 0);
};

//转移动画：实际被打那个人触发转移时播放的动画，时点-伤害转移之前
Game_Battler.prototype.transferDamageAnimationId = function(){
    return 20; //用8号动画【光球】做测试
};

//转移执行动画：实际执行伤害转移时同步执行的转移动画，时点-伤害转移执行时
Game_Battler.prototype.transferExecAnimationId = function(){
    return 21;
};

//伤害转移主逻辑：如果存在转移目标，执行转移
const SWDA_TransferDamage_invokeNormalAction = BattleManager.invokeNormalAction;
BattleManager.invokeNormalAction = function(subject, target){
    const transferTarget = this.getTransferActionTarget(subject, target);
    if(!!transferTarget)
        this.invokeTransferAction(subject, target, transferTarget);
    else
        SWDA_TransferDamage_invokeNormalAction.call(this, subject, target);
};

BattleManager.invokeTransferAction = function(subject, target, transferTarget){
    this._logWindow.displayTransferDamage(subject, target, transferTarget, this._action);
    this._action.apply(transferTarget);
    this._logWindow.displayActionResults(subject, transferTarget);
    this._logWindow.waitForAnimation();
    if(transferTarget.isDead())
        transferTarget.performCollapse();
    transferTarget.setTransferDamageFlag(false);
};

//转移到的目标，如果返回 null，就是没有转移
BattleManager.getTransferActionTarget = function(subject, target){
    if(this._action.isDamage() && target.isStateAffected(150))
        return this._action.subject();
    else
        return null;
};

//播放转移效果
Window_BattleLog.prototype.displayTransferDamage = function(subject, target, transferTarget, action){
    transferTarget.setTransferDamageFlag(true);
    target.performTransferDamage();
    const animationId = action.item().animationId;
    this.showNormalAnimation([transferTarget], transferTarget.transferExecAnimationId());
    this.showNormalAnimation([transferTarget], animationId);
};